package org.gourpg.entity.log;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Timestamp;
import java.util.Objects;


@Entity
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Table(name = "system_running_log")
public class SystemRunningLog {

    /**
     * 纯主键ID，多维雪花算法
     */
    @Id
    private Long logId;
    /**
     * 操作员ID，可能为空，取不到人的时候为空
     */
    private Integer logPersonId;
    /**
     * 开始时间
     */
    private Timestamp logStartTime;
    /**
     * 结束时间
     */
    private Timestamp logEndTime;
    /**
     * 执行功能类型（注解中填写）
     */
    private String logClassType;
    /**
     * 执行功能名称（注释中填写）
     */
    private String logClassName;
    /**
     * 执行功能地址
     */
    private String logClassPath;
    /**
     * 时间间隔(毫秒)
     */
    private Integer logTimeInterval;

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        SystemRunningLog that = (SystemRunningLog) o;
        return getLogId() != null && Objects.equals(getLogId(), that.getLogId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
